package com.guang.elegantshutdowm.executor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CopyFilePageSafelyDestroyExecutor extends ThreadPoolTaskExecutor {

    private static final Logger logger = LoggerFactory.getLogger(CopyFilePageSafelyDestroyExecutor.class);


    @Override
    public void destroy() {
        ThreadPoolExecutor threadPoolExecutor = this.getThreadPoolExecutor();
        threadPoolExecutor.shutdown();

        while(!threadPoolExecutor.isTerminated()) {
            try {
                threadPoolExecutor.awaitTermination(50L, TimeUnit.MILLISECONDS);
                logger.warn("CopyFilePageSafelyDestroyExecutor is terminating!");
            } catch (InterruptedException var3) {
                logger.error("CopyFilePageSafelyDestroyExecutor shutdown is interrupted but ignored!", var3);
            }
        }

        logger.info("CopyFilePageSafelyDestroyExecutor is terminated!");
    }
}